package com.ruix.app.model;

import android.text.TextUtils;

import org.json.JSONObject;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by hadexs on 2017/4/19.
 */

public class Comment implements Serializable{
    private String ID;
    private String pid;
    private String authorId;
    private String authorName;
    private String authorAvatar;
    private String content;
    private long creatTime;
    private String replyName;
    private String replyID;


    public Comment parse(JSONObject object){
        if (object != null) {
            setID(object.optString("id",""));
            setPid(object.optString("pid",""));
            setAuthorId(object.optString("author_id",""));
            setAuthorName(object.optString("author_name",""));
            setAuthorAvatar(object.optString("author_avatar",""));
            setContent(object.optString("content",""));
            long creatTime = object.optLong("created_at",0) * 1000;
            setCreatTime(creatTime);
            setReplyID(object.optString("reply_id",""));
            setReplyName(object.optString("reply_name",""));
        }
        return this;
    }

    public String getID() {
        return ID;
    }

    public void setID(String ID) {
        this.ID = ID;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public String getAuthorId() {
        return authorId;
    }

    public void setAuthorId(String authorId) {
        this.authorId = authorId;
    }

    public String getAuthorName() {
        return authorName;
    }

    public void setAuthorName(String authorName) {
        this.authorName = authorName;
    }

    public String getAuthorAvatar() {
        return authorAvatar;
    }

    public void setAuthorAvatar(String authorAvatar) {
        this.authorAvatar = authorAvatar;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public long getCreatTime() {
        return creatTime;
    }

    public void setCreatTime(long creatTime) {
        this.creatTime = creatTime;
    }

    public String getReplyName() {
        return replyName;
    }

    public void setReplyName(String replyName) {
        this.replyName = replyName;
    }

    public String getReplyID() {
        return replyID;
    }

    public void setReplyID(String replyID) {
        this.replyID = replyID;
    }


    public boolean isReply(){
        if (!TextUtils.isEmpty(this.replyID)
                && !TextUtils.isEmpty(this.replyName)
                && !"null".equals(this.replyName)
                ) {
            return true;
        } else {
            return false;
        }


    }


//    public void buildeDisplayTime() {
//        if (createdTime > 0) {
//            SimpleDateFormat format = new SimpleDateFormat("M月d日");
//            Date d1 = new Date(createdTime);
//            createdTimeDisplay = format.format(d1);
//        }
//    }


    @Override
    public String toString() {
        return "Comment{" +
                "ID='" + ID + '\'' +
                ", pid='" + pid + '\'' +
                ", authorId='" + authorId + '\'' +
                ", authorName='" + authorName + '\'' +
                ", authorAvatar='" + authorAvatar + '\'' +
                ", content='" + content + '\'' +
                ", creatTime=" + creatTime +
                ", replyName='" + replyName + '\'' +
                ", replyID='" + replyID + '\'' +
                '}';
    }
}
